home *** CD-ROM | disk | FTP | other *** search
/ Netware Super Library / Netware Super Library.iso / pgm_tool / lu62 / comm / appl.c next >
C/C++ Source or Header  |  1995-07-03  |  16KB  |  463 lines

  1.  
  2.   /************************************************************************
  3.                          APPL
  4.   **************************************************************************/
  5.  
  6.   #include <stdio.h>
  7.   #include "include.h"
  8.   #include <malloc.h>
  9.   #include <state1.h>
  10.   #include <dos.h>
  11.   #define RESRU 19
  12.   #define RESRH 16
  13.   #define APPC 0x68            /* 1068 */
  14.  
  15.  
  16. extern struct segprf *preqseg(int n);
  17. extern struct rqb *preqrq(int n);
  18. extern void pattach(int n,char far *pdata,int len);
  19. extern void prelseg(struct segprf *wseg);
  20. extern void prelrq(struct rqb *wrqb);
  21. extern void delhscb(struct hscb *whscb);
  22.  
  23.  
  24.   extern struct rqb *appl1(struct rqb *wrqb);
  25.   struct rqb *apost(short i,short k,unsigned char n);
  26.  
  27.   void Call_APPC(unsigned char RecForm,void far *p);
  28.  
  29.   struct rqb *findrqb(char *(*pq),short syscr);
  30.   int bu_seg(short n, unsigned char t,char *p,struct hscb *whscb);
  31.  
  32. struct hscb *crhscb( char *mylu, char *partlu);
  33. struct hscb *findhscb( unsigned long ccor );
  34.      int rqbind(struct rqb *wrqbb);
  35.      int unbind(struct rqb *wrqbb);
  36.      int rqsend(struct rqb *wrqbb);
  37.      int rspbind(struct rqb *wrqbb);
  38.      int rspunbnd(struct rqb *wrqbb);
  39.  
  40.  
  41.  
  42.   struct rqb *appl(wrqb)
  43.   struct rqb *wrqb;
  44.   {
  45.      int parm,n,rtncd;
  46.      struct rh *wrh;
  47.      union ru *wru;
  48.      struct segprf *wseg;
  49.  
  50.      if (!(wrqb->th.ra.code & FROM))
  51.             {
  52.                      return (appl1(wrqb));
  53.             }
  54.      wseg=(struct segprf *)((char*)wrqb-12);
  55.      if (wseg -> len < 3 )
  56.              return 0;
  57.      wru=(char*)wrqb+RESRU;
  58.      wrh=(char*)wrqb+RESRH;
  59.      if (wrh->rh[0] & RSP)
  60.          goto RESP;
  61.      if ((wrh->rh[0] == 0x6b) & (wrh->rh[1] == 0x80) )
  62.           {
  63.               if (wru->cru[0]==0x31) {
  64.           rtncd=rqbind(wrqb); goto BAC; }
  65.               if (wru->cru[0]==0x32) {
  66.           rtncd=unbnd(wrqb); goto BAC; }
  67.          }
  68.      rtncd=rqsend(wrqb);
  69.      goto BAC;
  70.      RESP: n=0;
  71.            if (wrh->rh[1] & ERTI)
  72.                 n=2;
  73.            if (wru->cru[n]==0x31) {
  74.           rtncd=rspbind(wrqb);goto BAC; }
  75.            if (wru->cru[n]==0x32) {
  76.           rtncd=rspunbnd(wrqb);goto BAC;}
  77.            rtncd=rqsend(wrqb);
  78.      BAC:
  79.       return 0;
  80.      } /************ end of APPL ***************/
  81.      /**************** BIND ******************/
  82.      int rqbind(wrqbb)
  83.      struct rqb *wrqbb;
  84.      {
  85.      struct th *wth;
  86.      struct rqb *wpost;
  87.      union ru *wru;
  88.      struct bind *wbind;
  89.      struct nau *wnau;
  90.      struct hscb *whscb;
  91.      struct rh *wrh;
  92.      short netaddr;
  93.      char *cor;
  94.      int i;
  95.  
  96.      wbind=(char*)wrqbb+RESRU;
  97.      whscb=crhscb(wbind->slu,wbind->plu);
  98.      whscb->cor=wrqbb->th.ra.wa.hh.hscb;
  99.      wrh=(char*)wrqbb+RESRH;
  100.      wrh->rh[0] |= RSP;
  101.      wrh->rh[1]=0;
  102.      wrqbb->link=NULL;                     /* 0172 */
  103.      wrqbb->th.ra.stcb=FISC_CODE;
  104.      wrqbb->th.ra.code=0x02;
  105.      wrqbb->th.ra.code |= FROM;        /* 0172 */
  106.      wth=&(wrqbb->th.th);
  107.      /* memcpy (&netaddr,&(wth->dest.lan.daf),2); */
  108.      /* memcpy (&(wth->dest.lan.daf),&(wth->dest.lan.oaf),2); */
  109.      /* memcpy (&(wth->dest.lan.oaf),&netaddr,2); */
  110.     /*     wth->t13.rout.tnpath |= TPATH;  */ /* 0172 */
  111.      pattach (1,wrqbb,4);
  112.      wpost=apost(1,11,1);         /* 0279 */
  113.      if (wpost==NULL)
  114.         return 0;
  115.      wpost->th.ra.wa.hh.hscb=whscb->cor;
  116.      wru=(char*)wpost+RESRU;
  117.      memcpy (wru,&(whscb->hslunam[0]),8);
  118.      Call_APPC (1,wpost);       /*@2003 */
  119.      return 0 ;
  120.  
  121.      }/***************** end of bind **************/
  122.      /****************** RSP(BIND) **************/
  123.      int rspbind(wrqbrb)
  124.      struct rqb *wrqbrb;
  125.      {
  126.         struct segprf *wsegbf;
  127.         struct rqb *wrqbbf,*wpost;
  128.         struct th *wth;
  129.         struct rh *wrh;
  130.         union ru *wru,*wrup;
  131.         struct hscb *whscb;
  132.         struct bind *wbind;
  133.         struct rqb *wrqbq;
  134.         struct nau *wnau;
  135.         struct segprf *wseg;
  136.         short i;
  137.         wseg=(struct segprf *)((char*)wrqbrb-12);
  138.           wrh=(char*)wrqbrb+RESRH;
  139.           wru=(char*)wrqbrb+RESRU;
  140.           whscb=findhscb(wrqbrb->th.ra.wa.hh.hscb);
  141.           wnau=whscb->naup;
  142.           wth=&(wrqbrb->th.th);
  143.           if ((wrh->rh[1] & ERTI) == 0)
  144.                 goto POSRSP;
  145.           wbind=&(wru->cru[2]);
  146.              wseg->link=NULL;   /*5002*/
  147.              wrqbrb->link=NULL; /*5002*/
  148.           prelseg(wseg);
  149.             wrqbq=findrqb(&(wnau->opnq),wth->t912.old.snf); /* 1068 */
  150.           if (wrqbq==NULL)
  151.                 return 0;
  152.           wrqbq->th.ra.rparm.parm.parm1=5;
  153.           wrqbq->th.ra.rparm.parm.parm2=0xff;
  154.           wrqbq->th.ra.code=0xda;
  155.           Call_APPC(5,wrqbq);     /* @2003 */
  156.            return 0;
  157.         POSRSP:
  158.            wrqbq=findrqb(&(wnau->opnq),wth->t912.old.snf);  /* 1068 */
  159.            if (wrqbq==NULL)
  160.               { wpost=apost(1,19,1);         /* 0279 */   /* 2005 */
  161.                 if(wpost==NULL)
  162.             return 0;
  163.                 wpost->th.ra.wa.hh.hscb=whscb->cor;
  164.                 wrup=(char*)wpost+RESRU;
  165.                  memcpy (wrup,&(whscb->hslunam[0]),8);
  166.                  memcpy (wrup+8,&(whscb->hsnodnam[0]),8);    /* 2005 */
  167.         Call_APPC(1,wpost);          /* @2003 */
  168.              wseg->link=NULL;   /*5002*/
  169.              wrqbrb->link=NULL; /*5002*/
  170.                 prelseg (wseg);
  171.                 return 0;
  172.               }
  173.           wrqbq->th.ra.rparm.parm.parm1=5;
  174.           wrqbq->th.ra.rparm.parm.parm2=0xff;
  175.           wrqbq->th.ra.code=0xc2;
  176.           wrqbq->th.ra.wa.hh.hscb=whscb->cor;
  177.          Call_APPC(5,wrqbq);        /* @2003  */
  178.              wseg->link=NULL;   /*5002*/
  179.              wrqbrb->link=NULL; /*5002*/
  180.           prelseg(wseg);
  181.           return 0;
  182.     }  /***************end of rsp(bind)**********************/
  183.     /********************** SEND ********************************/
  184.      int rqsend(wrqbs)
  185.      struct rqb *wrqbs;
  186.     {
  187.         int i,k;
  188.         struct nau *wnau;
  189.         struct hscb *whscb;
  190.         unsigned char type;
  191.     struct rh *wrh;
  192.     union ru *wru;
  193.     char *pru,*prh;
  194.     struct segprf *wseg;
  195.     wseg=(struct segprf *)((char*)wrqbs-12);
  196.     whscb=findhscb(wrqbs->th.ra.wa.hh.hscb);
  197.        wnau=whscb->naup;
  198.  
  199.       wrh=(char*)wrqbs+RESRH;
  200.       prh = wrh;
  201.     wru=(char*)wrqbs+RESRU;
  202.     pru = wru;
  203.     i=wseg -> len - 3 ;
  204.         if ( i == 0 )
  205.                 {
  206.                   if ( ((*prh & 0x0b) == 0x0b) && ((*(prh+1) & 0x80) == 0x80) )
  207.                         {
  208.                           type= Request_to_send;
  209.                           bu_seg(0,type,NULL,whscb);
  210.                         }
  211.                   if ( ((*prh & 0x81) == 0x81) && ((*(prh+1) & 0xa0) == 0xa0) )
  212.                         {
  213.                           type= COnfirmed;
  214.                           bu_seg(0,type,NULL,whscb);
  215.                         }
  216.        if ( (*(prh+2) & 0x21 )  == 0 )
  217.             {   /* no change dir */
  218.                  if ( (((*prh) & 0x01 ) == 0x01) && (((*(prh+1)) & 0xa0) == 0xa0))
  219.                           { type = Confirm;
  220.                             bu_seg(0, type, NULL,whscb);
  221.                           }
  222.             }
  223.        if ( ((*(prh+2)) & 0x20) == 0x20 ) /* prep to rec */
  224.             {
  225.                 if ( (*(prh+1) & 0xb0 ) == 0x90)   /* flush */
  226.                            type = PREP_TO_RCV_FLUSH;
  227.                 if ( (*(prh+1) & 0xb0 ) == 0xa0)   /* short */
  228.                            type = PREP_TO_RCV_CONFIRM_SH;
  229.                 if ( (*(prh+1) & 0xb0 ) == 0xb0)   /* long */
  230.                            type = PREP_TO_RCV_CONFIRM_LG;
  231.                 bu_seg( 0, type,NULL,whscb);
  232.             }
  233.        if ( ((*(prh+2)) & 0x01 ) == 0x01)   /* deallocate */
  234.             {
  235.                 if ( (*(prh+1) & 0xb0 ) == 0xa0)   /* conf */
  236.                            type = Deallocate_confirm;
  237.                 if ( (*(prh+1) & 0xb0 ) == 0xb0)   /* flush */
  238.                            type = Deallocate_flush;
  239.                 bu_seg( 0, type,NULL,whscb);
  240.             }
  241.           goto ALLOK;
  242.                 }
  243.        if ( (*prh & 0x08) == 0x08 )   /* FMH */
  244.             { k= *pru;      /* FMH length */
  245.              type= Fmh;
  246.              bu_seg(k,type,pru,whscb);
  247.              if (i > k)      /* FMH + data */
  248.                     { memcpy (pru,pru+k,i-k);
  249.                       wseg -> len -= k;
  250.                     }
  251.              i -= k;
  252.             }
  253.  
  254.        if ( (*(prh+2) & 0x21 )  == 0 )
  255.             {   /* no change dir */
  256.                  if ( (((*prh) & 0x01 ) == 0x01) && (((*(prh+1)) & 0xa0) == 0xa0))
  257.                           { type = Confirm;
  258.                             bu_seg(0, type, NULL,whscb);
  259.                           }
  260.             }
  261.        if ( i != 0 )
  262.             {
  263.              type= Send_data;
  264.              bu_seg( i, type,pru,whscb);
  265.            }
  266.        if ( ((*(prh+2)) & 0x20) == 0x20 ) /* prep to rec */
  267.             {
  268.                 if ( (*(prh+1) & 0xb0 ) == 0x90)   /* flush */
  269.                            type = PREP_TO_RCV_FLUSH;
  270.                 if ( (*(prh+1) & 0xb0 ) == 0xa0)   /* short */
  271.                            type = PREP_TO_RCV_CONFIRM_SH;
  272.                 if ( (*(prh+1) & 0xb0 ) == 0xb0)   /* long */
  273.                            type = PREP_TO_RCV_CONFIRM_LG;
  274.                 bu_seg( 0, type,NULL,whscb);
  275.             }
  276.        if ( ((*(prh+2)) & 0x01 ) == 0x01)   /* deallocate */
  277.             {
  278.                 if ( (*(prh+1) & 0xb0 ) == 0xa0)   /* conf */
  279.                            type = Deallocate_confirm;
  280.                 if ( (*(prh+1) & 0xb0 ) == 0xb0)   /* flush */
  281.                            type = Deallocate_flush;
  282.                 bu_seg( 0, type,NULL,whscb);
  283.             }
  284.         ALLOK:
  285.         wseg->link = NULL;
  286.         wrqbs->link = NULL;
  287.         prelseg(wseg);
  288.              return 0;
  289.     } /******************************************************************/
  290.     bu_seg (k, t , ptr,whscb)
  291.             short k;
  292.             unsigned char t;
  293.             char *ptr;
  294.             struct hscb *whscb;
  295.                 {
  296.                     struct  rqb *wpost;
  297.             struct nau *wnau;
  298.             struct segprf *wseg;
  299.             struct rh *wrh;
  300.             union ru *wru;
  301.                        wnau=whscb->naup;
  302.  
  303.                        if ( t == Fmh)
  304.                            wpost=apost(1,k+3,0);       /* 0279 */
  305.                        else
  306.                            wpost=apost(1,k+3,4);       /* 0279 */
  307.                        if (wpost==NULL)
  308.                             {
  309.                                 wpost = apost(0,0,7);
  310.                                 memcpy (&(wpost->th.ra.wa.area[0]),&(whscb->hslunam),8);
  311.             Call_APPC(7,wpost);       /* 1070 */
  312.                                  prelrq(wpost);
  313.                                  return 0;
  314.                              }
  315.                        memcpy (&(wpost->th.ra.wa.area[0]),&(whscb->hslunam),8);
  316.                        if (k != 0)
  317.                            {
  318.                  wru=(char*)wpost+RESRU;
  319.                  memcpy(wru,ptr,k);
  320.                            }
  321.                wrh=(char*)wpost+RESRH;
  322.                wrh->rh[0]= t ;
  323.         if (t == Fmh)
  324.               Call_APPC(0,wpost);       /* 1070 */
  325.         else
  326.                Call_APPC(4,wpost);     /* 1070 *//* @2003 */
  327.          wseg=(struct segprf *)((char*)wpost - 12);
  328.              wseg->link=NULL;   /*5002*/
  329.          wpost->link=NULL;  /*5002*/
  330.              prelseg(wseg);
  331.  
  332.         return 0;
  333.      }/************** end of bu_seg *******************/
  334.      unbnd(wrqbu)
  335.      struct rqb *wrqbu;
  336.     {
  337.     struct th *wth;
  338.         struct rh *wrh;
  339.         short netaddr;
  340.         struct rqb *wpost;
  341.         struct nau *wnau;
  342.         struct hscb *whscb;
  343.         struct segprf *wseg;
  344.         wrh=(char*)wrqbu+RESRH;
  345.         wrh->rh[0] |= RSP;
  346.         wrh->rh[1]=0;
  347.         wth=&(wrqbu->th.th);
  348.         memcpy (&netaddr,&(wth->dest.lan.daf),2);
  349.         memcpy (&(wth->dest.lan.daf),&(wth->dest.lan.oaf),2);
  350.         memcpy (&(wth->dest.lan.oaf),&netaddr,2);
  351.         wth->t13.rout.tnpath |= TPATH;
  352.     whscb=findhscb(wrqbu->th.ra.wa.hh.hscb);
  353.     wnau=whscb->naup;                        /* @2002 */
  354.         wseg=(struct segprf *)((char*)wrqbu-12);
  355.         wrqbu->th.ra.stcb=DFC_CODE;
  356.         wrqbu->th.ra.code=0x02;
  357.         wrqbu->th.ra.code|=FROM;
  358.         pattach(1,wrqbu,3);
  359.         wpost=apost(0,0,2);           /* 0279 */
  360.         if (wpost==NULL)
  361.         return 0;
  362.            memcpy (&(wpost->th.ra.wa.area[0]),&(whscb->hslunam),8);
  363.           Call_APPC(2,wpost);        /* @2003 */
  364.           delhscb(whscb);
  365.            return 0;
  366.       } /************** end of unbind ***************************/
  367.       /***************** RSP(UNBIND) ****************************/
  368.      int rspunbnd(wrqbru)
  369.      struct rqb *wrqbru;
  370.      {
  371.         struct segprf *wseg;
  372.     struct hscb *whscb;
  373.  
  374.        whscb=findhscb(wrqbru->th.ra.wa.hh.hscb);
  375.        wseg=(struct segprf *)((char*)wrqbru-12);
  376.           wseg->link=NULL;   /*5002*/
  377.           wrqbru->link=NULL;  /*5002*/
  378.        prelseg(wseg);
  379.        delhscb(whscb);
  380.        return 0;
  381.     }/***************** end of rsp(unbind) ************************/
  382.     /*************** request RQB or SEG for post *******************/
  383.     struct rqb *apost( i,k,n)           /* 0279 */
  384.      short i;   /*0-RQB,1-SEG*/
  385.      short k;   /*length RU for SEG*/
  386.      unsigned char n;   /*request code*/
  387.      {
  388.         struct rqb *wrqb;
  389.         struct segprf *wseg;
  390.         if (i==0) /* RQB */
  391.                 {wrqb=preqrq (1);
  392.                  if (wrqb==NULL)
  393.             {
  394.                          return (NULL);
  395.                         }
  396.                  wrqb->th.ra.code=0;
  397.                  wrqb->th.ra.code|=RTYPE;
  398.                }
  399.             else /* SEG */
  400.                 {
  401.                  wseg=preqseg(k);
  402.                  if (wseg == NULL)
  403.             {
  404.                          return (NULL);
  405.                         }
  406.                  wseg->flag=0;
  407.                  wseg->link=NULL;
  408.                  wrqb=(struct rqb*)((char*)wseg+12);
  409.                  wrqb->th.ra.code=0;
  410.                  wseg->len=k;
  411.                }
  412.         wrqb->link=NULL;
  413.         wrqb->th.ra.code|=2;
  414.         wrqb->th.ra.code|=FROM;
  415.         wrqb->th.ra.rparm.parm.parm2=0xff;
  416.         wrqb->th.ra.rparm.parm.parm1=n;
  417.         return (wrqb);
  418.    }/******* end of post ************************/
  419.    /******** find RQB in queue *******************/
  420.    struct rqb *findrqb (pq,syscr)
  421.    char *(*pq);
  422.    short syscr;
  423.   {
  424.         short usrcr;
  425.         struct rqb *prqb,*mrqb;
  426.             prqb=*pq;
  427.  
  428.  
  429.  
  430.             if (prqb==NULL)
  431.                     return (NULL);
  432.             memcpy (&usrcr,&(prqb->th.ra.wa.area[0]),2);
  433.             if (usrcr==syscr)
  434.                     {*pq=prqb->link;
  435.                       return (prqb);
  436.                     }
  437.             mrqb=prqb;
  438.             while (prqb->link!=NULL)
  439.                     {prqb=prqb->link;
  440.                      memcpy (&usrcr,&(prqb->th.ra.wa.area[0]),2);
  441.                      if (usrcr==syscr)
  442.                             {mrqb->link=prqb->link;
  443.                              return (prqb);
  444.                             }
  445.                      mrqb=prqb;
  446.                     }
  447.             return (NULL);
  448.      }/******* end of findrqb *****************/
  449. #if OS_TYPE == 0                 /* @2003 */
  450.     void Call_APPC(RecForm,p)
  451.     unsigned char RecForm;
  452.         void far *p;
  453.          {
  454.             union REGS inregs,outregs;
  455.             struct SREGS segregs;
  456.                 inregs.x.ax=RecForm*256+255;
  457.                 segregs.ds=FP_SEG(p);
  458.                 inregs.x.dx=FP_OFF(p);
  459.                 int86x( APPC,&inregs,&outregs,&segregs);
  460.          }
  461. #endif                     /* @2003 */
  462.      /****************THE END*************************************/
  463.